﻿using System.Collections.Generic;
using DAL;
using Entity;
using Utilities;

namespace Business
{
	public class OutCategoryBusiness
	{
		#region code CMS

        /// <summary>
        /// CateType: (0:Sản phẩm) ---- (1:Tin tức) 
        /// </summary>
        /// <param name="catetype"></param>
        /// <param name="catstt"></param>
        /// <returns></returns>
        public static List<OutCategory> GetOutCategoryList(int catetype, int catstt)
        {
            var result = FreshCmsDataAccessProvider.OutCategory.GetOutCategoryList(catetype, catstt);
            result = reFormatList(result);
            return result;
        }

        public static List<OutCategory> GetOutCategoryChildList(int cateParentId, int catstt)
        {
            var result = FreshCmsDataAccessProvider.OutCategory.GetOutCategoryChildList(cateParentId, catstt);
            result = reFormatList(result);
            return result;
        }

        public static int UpdateOutCategory(OutCategory OutCategory)
        {
            var result = FreshCmsDataAccessProvider.OutCategory.UpdateOutCategory(OutCategory);
            return result;
        }

        /// <summary>
        /// Action: 0: Down cate, 1: Up cate
        /// </summary>
        /// <param name="catId"></param>
        /// <param name="catParent"></param>
        /// <param name="catType"></param>
        /// <param name="action"></param>
        /// <returns></returns>
        public static int OrderOutCategory(int catId, int catParent, int catType, int action)
        {
            var result = FreshCmsDataAccessProvider.OutCategory.OrderOutCategory(catId, catParent, catType, action);
            return result;
        }

        public static int DeleteOutCategory(int catId, int catType)
        {
            var result = FreshCmsDataAccessProvider.OutCategory.DeleteOutCategory(catId, catType);
            return result;
        }

        private static List<OutCategory> reFormatList(List<OutCategory> lst)
        {
            if (lst != null && lst.Count > 0)
            {
                foreach (OutCategory item in lst)
                {
                    item.CatUri = UnicodeUtility.UnicodeToKoDauAndGach(item.CatName);
                }
                return lst;
            }
            return new List<OutCategory>();
        }

		#endregion
	}
}